package com.jingjiu.homeservicesbiz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingjiu.homeservicesapi.domain.ForumComment;
import com.jingjiu.homeservicesapi.domain.ForumPost;
import com.jingjiu.homeservicesapi.util.R;
import com.jingjiu.homeservicesbiz.service.ForumCommentServiceImpl;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
*功能：
 作者：chenhao
*日期： 2025/4/21 下午1:55
*/
@RestController
@RequestMapping("/system/comment")
public class ForumCommentController {

    @Autowired
    private ForumCommentServiceImpl forumCommentService;
//    @GetMapping("/page")
//    public R<Page<ForumComment>> getPage(@ParameterObject Page<ForumComment> page,
//                                      @ParameterObject ForumComment forumComment) {
//
//
//        // 调用 Service 层进行分页查询
//        return R.ok(forumCommentService.selectPage(page, forumComment));
//    }




    /**
     * 导出论坛帖子：记录用户发布的内容列表
     */

    @PostMapping("/list")
    @ResponseBody
    public R<List<ForumComment>> list(@RequestBody ForumComment forumComment)
    {
        List<ForumComment> forumComments = forumCommentService.selectForumCommentList(forumComment);
        if(forumComments==null)
            return R.failed();
        return R.ok(forumComments);

    }



    /**
     * 新增保存论坛帖子：记录用户发布的内容
     */

    @PostMapping("/add")
    @ResponseBody
    public R addSave(@RequestBody ForumComment forumComment)
    {
        int row = forumCommentService.insertForumComment(forumComment);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }


    /**
     * 按id获取
     *
     * @param id   本我

     * @return {@link ForumPost }
     */

    @GetMapping("/get/{id}")
    public R<ForumComment> getById(@PathVariable("id") Long id)
    {
        ForumComment forumComment = forumCommentService.selectForumCommentById(id);
        if(forumComment==null)
            return R.failed();
        return R.ok(forumComment);

    }

    @PostMapping("/edit")
    @ResponseBody
    public R editSave(@RequestBody ForumComment forumComment)
    {
        int row = forumCommentService.updateForumComment(forumComment);
        if(row!=1)
            return R.failed();

        return R.ok(row);
    }

    /**
     * 删除论坛帖子：记录用户发布的内容
     */

    @PostMapping( "/remove")
    @ResponseBody
    public R  remove(Long id)
    {
        System.out.println(id);
        int row = forumCommentService.deleteForumCommentById(id);
        if(row!=1)
            return R.failed();
        return R.ok(row);
}
}
